# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper


  def select_users_project_leader
    arr=[  ]
    users=User.find(:all)
    for user in users
      if user.role.id==2
        arr << [ h(user.complete_name),user.id ]
      end
    end

    #this is for skip the final s of the controller name (necessary for the view form and mass si)
    c=String(controller.controller_name)
    if( c.slice(c.size-1,c.size-1)=="s" )
      c=c.slice(0,c.size-1)
    end

    return select(c,:user_id,arr)
  end


  def select_role
    if (current_user.role_id==1)
      roles_array=Role.find :all
    else
      roles_array=Role.find(:all, :conditions=>'id!=1 and id!=2')
    end
    
    @roles=[  ]
    for c_role in roles_array
      @roles<<[ h(c_role.nombre),c_role.id ]
    end
    
    c=String(controller.controller_name)
    if( c.slice(c.size-1,c.size-1)=="s" )
      c=c.slice(0,c.size-1)
    end
    return select(c,'role_id',@roles)
  end

  def select_user
    arr=[  ]
    users=User.find(:all, :conditions => "id != 1")
    for user in users
      arr << [ h(user.complete_name),user.id ]
    end

    #this is for skip the final s of the controller name (necessary for the view form and mass si)
    c=String(controller.controller_name)
    if( c.slice(c.size-1,c.size-1)=="s" )
      c=c.slice(0,c.size-1)
    end

    return select(c,:user_id,arr)
  end

  def select_project
    arr=[  ]
    if current_user.role_id==1
      projects=Project.find(:all)
    else
      projects=Project.find(:all,:conditions=>"user_id='"+current_user.id.to_s+"'")
    end
    for project in projects
      arr << [ h(project.name),project.id ]
    end

    c=String(controller.controller_name)
    if( c.slice(c.size-1,c.size-1)=="s" )
      c=c.slice(0,c.size-1)
    end
    return select(c,:project_id,arr)
  end


end
